# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gsm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.19
pkgrel=1
pkgdesc="Shared libraries for GSM 06.10 lossy speech compression (mingw-w64)"
arch=('any')
url="http://www.quut.com/gsm/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-yasm")
options=('strip' 'staticlibs')
source=("http://www.quut.com/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-adapt-makefile-to.mingw.patch
        0002-adapt-config-h-to.mingw.patch
        0003-fix-ln.mingw.patch)
sha256sums=('4903652f68a8c04d0041f0d19b1eb713ddcd2aa011c5e595b3b8bca2755270f6'
            '041f7a760eba8645e63dc3a83842959b13c07bd53f313f9db6420d5bad8c3a68'
            '4baaaf5218f384c7ee204da0617d6f95d3e2fc684faf5a80b892f29930939d07'
            '2985944c5c025822ff1cb4517fdaac87b55ccf967742287e7a8892fa01c66372')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver%.*}-pl${pkgver##*.}"
  patch -p1 -i ${srcdir}/0001-adapt-makefile-to.mingw.patch
  patch -p1 -i ${srcdir}/0002-adapt-config-h-to.mingw.patch
  patch -p1 -i ${srcdir}/0003-fix-ln.mingw.patch
}

build() {
  cp -r ${srcdir}/${_realname}-${pkgver%.*}-pl${pkgver##*.} ${srcdir}/build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  # Prepare directories
  install -m755 -d "${pkgdir}${MINGW_PREFIX}"/{bin,lib,include,share/{licenses/${_realname},man/man{1,3}}}

  make -j1 INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" install

  # Install license
  install -m644 COPYRIGHT ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/license.txt
}
